package edu.stu.cs.software.family.warehouse.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.stereotype.Service;

import edu.stu.cs.software.family.base.service.impl.GenericManagerImpl;
import edu.stu.cs.software.family.warehouse.dao.CategoryDao;
import edu.stu.cs.software.family.warehouse.domain.Category;
import edu.stu.cs.software.family.warehouse.service.CategoryManager;
@Service(value = "CategoryManager")
public class CategoryManagerImpl extends GenericManagerImpl<Category, Long> implements CategoryManager {

	CategoryDao categoryDao;
	@Override
	public List<Category> findByName(String name) {
		
		Category queryObject =new Category();
		queryObject.setCode(name);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("name", GenericPropertyMatchers.startsWith());
		Example<Category> ex = Example.of(queryObject, matcher);
		List<Category> result =this.categoryDao.findAll(ex);
		return result;
	}

	@Override
	public List<Category> findByCode(String code) {
		
		Category queryObject =new Category();
		queryObject.setCode(code);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("code", GenericPropertyMatchers.startsWith());
		Example<Category> ex = Example.of(queryObject, matcher);
		List<Category> result =this.categoryDao.findAll(ex);
		return result;
	}

	@Autowired
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
		this.dao=this.categoryDao;
	}
	
}
